package com.github.zdongcoding.recyclerviewlib;

import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.support.v7.widget.RecyclerView;

import com.github.zdg.recyclerview.RecyclerListAdapter;
import com.github.zdg.recyclerview.itemdecoration.ShaderItemDecoration;
import com.github.zdongcoding.recyclerviewlib.model.Item;
import com.github.zdongcoding.recyclerviewlib.viewholder.AnimalViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zoudong on 2017/5/27.
 */

public class DividerActivity extends SimpleActivity {
    private List<Item> data;

    @Override
    void initView() {
        mRecyclerView.addItemDecoration(mLinearDividerDecoration);
        data = new ArrayList<>();
        mRecyclerListAdapter = new RecyclerListAdapter<Item, AnimalViewHolder>(this, data) {

        };
        mRecyclerView.setAdapter(mRecyclerListAdapter);
    }

    @Override
    void initData() {
        data.add(new Item(R.drawable.ic_animal0, "小狗0"));
        data.add(new Item(R.drawable.ic_animal1, "小狗1"));
        data.add(new Item(R.drawable.ic_animal1, "小狗2"));
        data.add(new Item(R.drawable.ic_cartoon0, "小狗0"));
        data.add(new Item(R.drawable.ic_cartoon1, "小狗1"));
        data.add(new Item(R.drawable.ic_cartoon2, "小狗2"));
        data.add(new Item(R.drawable.ic_scenic0, "小狗0"));
        data.add(new Item(R.drawable.ic_scenic1, "小狗1"));
        data.add(new Item(R.drawable.ic_scenic2, "小狗2"));
        mRecyclerListAdapter.set(data);
        ShaderItemDecoration shaderItemDecoration = new ShaderItemDecoration(this, ShaderItemDecoration.SHADER_TOP);
        shaderItemDecoration.registerTopShaderCreator(new ShaderItemDecoration.ShaderCreator() {
            @Override
            public Shader createShader(RecyclerView parent) {
                return new LinearGradient(0, 0, 0, 300,
                        Color.parseColor("#FFFF0000"), Color.parseColor("#00000000"), Shader.TileMode.CLAMP);
            }
        });

    }

}
